package org.microsites.util;

import java.util.Hashtable;
import java.util.Map;

import org.microsites.domain.model.User;

public class UserContext {
	private User user;
	private Map<String, Object> map;

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	public Object put(String key, Object value) {
		if (this.map == null) this.map = new Hashtable<String, Object>();
		
		return this.map.put(key, value);
	}
	
	public Object get(String key) {
		if (this.map == null) this.map = new Hashtable<String, Object>();
		
		return this.map.get(key);
	}
	
	public boolean contains(String key) {
		if (this.map == null) this.map = new Hashtable<String, Object>();

		return this.map.containsKey(key); 
	}
	
	public void reset() {
		if (this.map != null) {
			this.map.clear();
			this.map = null;
		}
		this.user = null;
	}

	public boolean isAuthenticated() {
		return this.user != null;
	}
}
